package com.example.a84416.shiyan3;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends Activity implements View.OnClickListener {

    public TextView tv;
    @BindView(R.id.button6)
    Button btn6;
    @OnClick(R.id.button6)
    void btn6OnClick(View view)
    {
        tv.setText("ButterKnife框架绑定实现监听");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        tv = findViewById(R.id.textview);
        Button btn1 = findViewById(R.id.button1);
        Button btn2 = findViewById(R.id.button2);
        Button btn3 =findViewById(R.id.button3);
        Button btn4 = findViewById(R.id.button4);
        MyButtonlistener1 listener = new MyButtonlistener1();
        btn4.setOnClickListener(listener);
        Button btn5 = findViewById(R.id.button5);
        MyButtonlistener2 listener2 = new MyButtonlistener2();
        btn5.setOnClickListener(new MyButtonlistener2() {
            @Override
            public void onClick(View view) {
                tv.setText("使用外部类作为监听器");
            }
        });
         Button btn7=findViewById(R.id.button7);
         btn7.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
                 Intent intent=new Intent(MainActivity.this,ConfigurationTest.class);
                 startActivity(intent);
             }
         });
        Button btn8=findViewById(R.id.button8);
        btn8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(MainActivity.this,ProgressDialogTest.class);
                startActivity(intent);
            }
        });
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tv.setText("使用匿名内部类作为监听器");
            }
        });
        }
    public void clickButton(View view) {
        tv.setText("使用绑定到标签方式实现监听");

    }

    @Override
    public void onClick(View v) {
        //Activity作为监听器
        tv.setText("使用Activity作为监听器");
    }

    class MyButtonlistener1 implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            //内部类
            tv.setText("使用内部类作为监听器");
        }
    }

}

class MyButtonlistener2 implements View.OnClickListener {
    @Override
    public void onClick(View view) {

    }
}
